package smcms.service.order.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import smcms.commons.api.entity.result.CommonsResult;
import smcms.service.order.entity.OrderExportReq;
import smcms.service.order.entity.OrderReq;
import smcms.service.order.service.OrderService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/OrderController")
public class OrderController {
    @Autowired
    private CommonsResult commonsResult;
    @Autowired
    private OrderService orderService;

    @PostMapping("/insertOrder")
    public CommonsResult insertOrder(@RequestBody OrderReq req) {
        CommonsResult commonsResult = orderService.insertOrder(req);
        return commonsResult;
    }

    @PostMapping("/queryOrderList")
    public CommonsResult queryOrderList(@RequestBody OrderReq req) {
        CommonsResult OrderList = orderService.queryOrderList(req);
        return OrderList;
    }

    @PostMapping("/deleteOrderByIds")
    public CommonsResult deleteOrderByIds(@RequestBody Map<String, String> orderByIds) {
        CommonsResult commonsResult = orderService.deleteOrderByIds(orderByIds.get("orderIdList"));
        return commonsResult;
    }

    @PostMapping("/exportOrderList")
    public CommonsResult exportOrderList(@RequestBody OrderExportReq orderExportReq, HttpServletResponse response) {
        CommonsResult commonsResult = orderService.exportOrderList(orderExportReq, response);
        return commonsResult;
    }

    @PostMapping("/importTemplate")
    public CommonsResult importTemplate(@RequestBody OrderReq req, HttpServletResponse response) {
        orderService.importTemplate(req, response);
        return commonsResult.success();
    }

    @PostMapping("/importOrderList")
    public CommonsResult importOrderList(@RequestParam("file") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
        CommonsResult commonsResult = orderService.importOrderList(file, request, response);
        return commonsResult;
    }

    @PostMapping("/updateOrderInfo")
    public CommonsResult updateOrderInfo(@RequestBody OrderReq req) {
        CommonsResult commonsResult = orderService.updateOrderInfo(req);
        return commonsResult;
    }
}
